package com.itheima.strengthen.test02.entry;

import com.itheima.strengthen.test02.controller.jiutongController;
import com.itheima.strengthen.test02.controller.nuoshouController;
import com.itheima.strengthen.test02.domain.*;

import java.util.Random;
import java.util.Scanner;

public class Test {
    static nuoshouController nuoshouController = new nuoshouController();
    static jiutongController jiutongController = new jiutongController();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
//        int i = scanner.nextInt();

        NuoZhou nuoZhou = new NuoZhou("小学森之手",582,263,56.0);
        QSkill nZQSkill = new QSkill("大杀四方",30,40 + 1.05*nuoZhou.gethAttack());
        WSkill nZWSkill = new WSkill("致残打击",30,1.4*nuoZhou.gethAttack());
        ESkill nZESkill = new ESkill("亡者之拉",70,20 + 1.0*nuoZhou.gethAttack());
        setHero(nuoZhou, nZQSkill, nZWSkill, nZESkill);
        //发送诺手属性给后台
        nuoshouController.sendAtrribute(nuoZhou);

        Cask jiuTong = new Cask("古拉加斯",583,400,61.38);
        QSkill jTQSkill = new QSkill("欢乐时光",30,80 + 0.6*jiuTong.gethAttack());
        WSkill jTWSkill = new WSkill("醉酒狂暴",30,20 + 1.5*jiuTong.gethAttack());
        ESkill jTESkill = new ESkill("肉弹冲击",45,80 + 0.6*jiuTong.gethAttack());
        setHero(jiuTong, jTQSkill, jTWSkill, jTESkill);
        Random random = new Random();
        //发送酒桶属性给后台
        jiutongController.sendAtrribute(jiuTong);

//        while (i == 1){
        while (true){
            int attack = random.nextInt(14);
            if (attack % 2 ==0){
                //判断敌方是否存在
                if (jiuTong.gethHp() <= 0){
                    System.out.println("敌方狗带，游戏结束");
                    nuoZhou.speak();
                    break;
                }else {
                    //攻击
                    Skills skills = nuoshouController.attack(nuoZhou);
                    if (skills != null){
                        System.out.println(skills.getsName() + "!!!");
                        //诺手蓝量减少
                        jiuTong = jiutongController.hpAtrributeChange(skills);
                        nuoZhou = nuoshouController.mpAttributeChange(skills);
                        System.out.println(nuoZhou.gethName() + "消耗:" + skills.getsMp() + "MP，剩余蓝量:" + nuoZhou.gethMp());
                        //酒桶血量减少
                        System.out.println(jiuTong.gethName() + "消耗" + skills.getsAttack() + "HP，剩余血量" + jiuTong.gethHp());
                    }else {
                        //普通攻击
                        System.out.println("普通攻击!!!");
                        jiuTong = jiutongController.hpAtrributeChange(nuoZhou.gethAttack());
                        System.out.println(jiuTong.gethName() + "消耗" + nuoZhou.gethAttack() + "HP，剩余血量" + jiuTong.gethHp());
                    }
                }
        }else {
                //判断敌方是否存在
                if (nuoZhou.gethHp() <= 0){
                    System.out.println("敌方狗带，游戏结束");
                    jiuTong.speak();
                    break;
                }else {
                    //攻击
                    Skills skills = jiutongController.attack(jiuTong);
                    if (skills != null){
                        System.out.println(skills.getsName() + "!!!");
                        //诺手蓝量减少
                        jiuTong = jiutongController.mpAttributeChange(skills);
                        nuoZhou = nuoshouController.hpAtrributeChange(skills);
                        System.out.println(jiuTong.gethName() + "消耗:" + skills.getsMp() + "MP，剩余蓝量:" + jiuTong.gethMp());
                        //酒桶血量减少
                        System.out.println(nuoZhou.gethName() + "消耗" + skills.getsAttack() + "HP，剩余血量" + nuoZhou.gethHp());
                    }else {
                        //普通攻击
                        System.out.println("普通攻击!!!");
                        nuoZhou = nuoshouController.hpAtrributeChange(jiuTong.gethAttack());
                        System.out.println(jiuTong.gethName() + "消耗" + nuoZhou.gethAttack() + "HP，剩余血量" + jiuTong.gethHp());
                    }
                }

            }
        }
}


    private static void setHero(Hero hero, QSkill qSkill, WSkill wSkill, ESkill eSkill) {
        hero.setqSkill(qSkill);
        hero.setwSkill(wSkill);
        hero.seteSkill(eSkill);
    }
}
